package com.zhoutao.blog.seven.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhoutao.blog.seven.dao.model.ArticleDao;
import com.zhoutao.blog.seven.dao.model.TupleDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<ArticleDao> {

    @Select("<script>update article set read_count = read_count + 1 where id = #{id}</script>")
    void addReadCount(@Param("id") Long id);


    /**
     * 分页查询文章数据
     *
     * @param page
     * @param categoryId
     * @param tagId
     * @return
     */
    IPage<ArticleDao> find(
            @Param("page") IPage<ArticleDao> page,
            @Param("categoryId") Long categoryId,
            @Param("tagId") Long tagId,
            @Param("type") String type);

    /**
     * 按文章目录统计文章数量
     *
     * @param categoryIds
     * @return
     */
    List<TupleDao<Long, Long>> count(@Param("categoryIds") List<Long> categoryIds);


    @Select("<script>update article set comment_count = comment_count + 1 where id = #{id}</script>")
    void addCommentCount(@Param("id") Long id);
}
